import inquirer from 'inquirer'
import { exec, execSync } from 'child_process'

  ; (async function () {
    // @ts-ignore
    const { submit } = await inquirer.prompt({ name: "submit", type: "confirm", message: "是否需要提交git？", default: true })
    if (submit) {
      const store = execSync("git config --get credential.helper")
      if (store.toString() != "store") {
        execSync("git config credential.helper store")
      }

      // @ts-ignore
      const { commit } = await inquirer.prompt({ name: "commit", type: "input", message: "请输入提交信息" })
      exec(`git add . && git commit -m "${commit}" && git push`).stdout?.on("data", (data) => {
        console.log(`stdout: ${data}`);
      }).on("error", (err) => {
        return console.error(err);
      }).on("end", () => {
        console.log("提交成功");
      })
    }
  })()
